﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CourseManagerWPF
{
    /// <summary>
    /// FrmMain.xaml 的交互逻辑
    /// </summary>
    public partial class FrmMain : Window
    {
        public FrmMain()
        {
            InitializeComponent();
        }

        #region 无边框代码移动
        /// <summary>
        /// 无边框代码移动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            //获取鼠标相对标题栏的位置
            Point position = e.GetPosition(this);
            //如果鼠标再标题栏内，允许拖动
            if (e.LeftButton == MouseButtonState.Pressed)
            {
                if (position.X >= 0 && position.X < this.ActualWidth && position.Y >= 0 && position.Y < this.ActualHeight)
                {
                    this.DragMove();
                }
            }
        }
        #endregion

        /// <summary>
        /// 窗体关闭前的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //用户没有登录直接退出
            if (App.Teacher == null) return;
            MessageBoxResult result = MessageBox.Show("确认退出系统吗？", "退出提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
            if (result != MessageBoxResult.OK)
            {
                e.Cancel = true;
            }
        }

        private void btnClose_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// 学员管理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStudentManager_Click(object sender, RoutedEventArgs e)
        {
            //1.清空右边的窗体
            gridContent.Children.Clear();
            //2.new一个子窗体
            FrmManageStudent frmManageStudent = new FrmManageStudent();
            gridContent.Children.Add(frmManageStudent);
        }
    }
}
